export default class PETimer {
    private tID:number = 0;
    private tIDList:Array<number> = new Array<number>();
    
    private tmpTimeTasks:Array<PETimeTask> = new Array<PETimeTask>();
    private taskTime:Array<PETimeTask> = new Array<PETimeTask>();
    private recTidList:Array<number> = new Array<number>();

    private startTime:Date = new Date(1970,1,1,0,0,0,0);
    private nowTime:number;
    constructor()
    {
        this.tIDList = new Array<number>();
        this.tmpTimeTasks = new Array<PETimeTask>();
        this.taskTime = new Array<PETimeTask>();
        this.recTidList = new Array<number>();
    }

    public Update():void
    {

    }

    private CheckTimeTask()
    {
        for(let index = 0;index<this.tmpTimeTasks.length;index++)
        {
            this.taskTime.push(this.tmpTimeTasks[index]);
        }
        this.tmpTimeTasks = new Array<PETimeTask>();
        this.nowTime = this.GetUTCMilliscenond();
        for(let index=0;index<this.taskTime.length;index++)
        {
            let timeTask:PETimeTask = this.taskTime[index]
            if(this.nowTime<timeTask.delayTime)
            {
                continue;
            }else
            {
                let cd:Function = timeTask.callBack;
                if(cd!=null)
                {
                    cd();
                }
                if(timeTask.count==1)
                {
                    
                }
            }
        }
    }


    //获取1970/01/01以来的毫秒数
    private GetUTCMilliscenond():number
    {
        let ts:number = Date.now();
        return ts;
    }
}

class PETimeTask
{
    public tId:number;
    public delayTime:number;
    public callBack:Function;
    public count:number;
    public delay:number;
    constructor(tID:number,delayTime:number,callBack:Function,count:number,delay:number)
    {
        this.tId = tID;
        this.delayTime = delayTime;
        this.callBack = callBack;
        this.count = count;
        this.delay = delay;
    }
}

enum PETimeUnit
{
    MilliSecond,
    Second,
    Minute,
    Hour,
    Day
}